#!/usr/bin/perl -w
use strict;
use lib qw(lib);
use POSIX qw(strftime);
use Stdlog::Formatter;
use Benchmark;

my $iters = shift @ARGV || 1_000_000;


my $t = 0;
our $n = 0;
my @ltm = localtime;
my $fmtr1 = Stdlog::Formatter->new('/var/log/foobar.log');
my $fmtr2 = Stdlog::Formatter->new('/var/log/%{facility}/foobar.log');
my $fmtr3 = Stdlog::Formatter->new('/var/log/foobar/%{date}.log');
my $fmtr4 = Stdlog::Formatter->new('/var/log/%{facility}/foobar-%{date}.log');
my $fmtr5 = Stdlog::Formatter->new('/var/log/%{facility}/%{%Y-%m:date}/foobar-%{date}.log');

$t = time;

timethese(
    $iters,
    {
        'strftime'      => sub { my $s = strftime('%Y-%m-%d', localtime($t)) },
        'Static'        => sub { $fmtr1->({}); },
        'Facility'      => sub { $fmtr2->({'time' => $t}); },
        'Date'          => sub { $fmtr3->({'time' => $t}); },
        'Facility+date' => sub { $fmtr4->({'time' => $t}); },
        'Facility+2*date' => sub { $fmtr5->({'time' => $t}); },
    }
);

